#ifndef PIPEA_HPP
#define PIPEA_HPP

#include "pipe.hpp"
class PipeA : public Pipe
{
public:

	int operation;

public:

	PipeA()
		: Pipe()
		, operation(0)
	{

	}

	virtual HANDLE StartClient()
	{
		SHELLEXECUTEINFO lpExecInfo;
		lpExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);

		switch (operation)
		{
		case 0:
			lpExecInfo.lpFile = L"ur3Move.exe"; // name of file that you want to execute/ print/ or open/ in your case Adobe Acrobat.
			break;
		case 1:
			lpExecInfo.lpFile = L"ur3GetTCP.exe"; // name of file that you want to execute/ print/ or open/ in your case Adobe Acrobat.
			break;			
		}

		lpExecInfo.fMask = SEE_MASK_DOENVSUBST | SEE_MASK_NOCLOSEPROCESS;
		lpExecInfo.hwnd = NULL;
		lpExecInfo.lpVerb = NULL; // to open  program
		lpExecInfo.lpParameters = L""; //  file name as an argument
		lpExecInfo.lpDirectory = NULL;
		//lpExecInfo.nShow = SW_SHOW;  // show command prompt with normal window size 
		lpExecInfo.nShow = SW_HIDE;  // show command prompt with normal window size 
		lpExecInfo.hInstApp = (HINSTANCE)SE_ERR_DDEFAIL;   //WINSHELLAPI BOOL WINAPI result;
		ShellExecuteEx(&lpExecInfo);
		return lpExecInfo.hProcess;
	}


	bool SetPos(float x, float y, float z,
		float rx, float ry, float rz,
		std::string seg = ",")
	{		
		std::ostringstream oss;
		oss << x << seg << y << seg << z << seg
			<< rx << seg << ry << seg << rz << seg;
		std::string str = oss.str();
		operation = 0;
		return ServerWrite(str);
	}

	bool SetPos(cv::Vec6f p,
		std::string seg = ",")
	{
		return SetPos(p[0], p[1], p[2], p[3], p[4], p[5], seg);
	}

	bool SetPath(const std::vector<cv::Vec6f> &path,
		std::string seg = ",")
	{
		std::ostringstream oss;
		for (size_t i = 0;i<path.size();i++)
			oss << path[i][0] << seg << path[i][1] << seg << path[i][2] << seg
			<< path[i][3] << seg << path[i][4] << seg << path[i][5] << seg;
		std::string str = oss.str();
		operation = 0;
		return ServerWrite(str);
	}

	bool GetPos(cv::Vec6f &p,
		std::string seg = ",")
	{
		operation = 1;
		std::string str;
		if (ServerRead(str))
		{
			std::istringstream iss(str);
			char buf;
			iss >> p[0] >> buf
				>> p[1] >> buf
				>> p[2] >> buf
				>> p[3] >> buf
				>> p[4] >> buf
				>> p[5] >> buf;
			return true;
		}
		return false;
	}


};

#endif